import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { BranchEntity } from './entities/branch.entity';
import { Repository } from 'typeorm';
import { UserDto } from '../user/user.decorator';

@Injectable()
export class BranchService {
  constructor(
    @InjectRepository(BranchEntity)
    private readonly branchEntytyRep: Repository<BranchEntity>,
  ) {}

  async findAll(user: UserDto) {
    const entity = this.branchEntytyRep.createQueryBuilder('branch');
    const enterpriseId = user.enterpriseId;
    entity.andWhere('branch.enterprise_id = :enterpriseId', {
      enterpriseId,
    });
    const list = await entity.getMany();
    return list;
  }
}
